// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using System.Linq;
using NUnit.Framework;
using ValidationAspects;
using ValidationAspects.Exceptions;
using ValidationAspects.Factories;

namespace TestValidationAspects
{
	[TestFixture]
    public class TestNotNullOrWhiteSpaceAttribute
	{
		[Test]
		public void Test_get_Factory()
		{
            NotNullOrWhiteSpace factory = new NotNullOrWhiteSpaceAttribute().Factory as NotNullOrWhiteSpace;
			Assert.IsNotNull(factory);
		}

        [Test]
        public void Test_usage_null()
        {
            Dummy dummy = new Dummy { NotNullOrWhiteSpace = null };

            ValidationResult result = dummy.Validate();
            Assert.IsFalse(result.IsValid);
            Assert.AreSame(typeof(ValidateNotNullOrWhiteSpaceException), ((ValidationContextException)result.ValidationException).Flatten().First().GetType());
        }

        [Test]
        public void Test_usage_blank()
        {
            Dummy dummy = new Dummy { NotNullOrWhiteSpace = "   " };

            ValidationResult result = dummy.Validate();
            Assert.IsFalse(result.IsValid);
            Assert.AreSame(typeof(ValidateNotNullOrWhiteSpaceException), ((ValidationContextException)result.ValidationException).Flatten().First().GetType());
        }

        [Test]
        public void Test_usage_tab()
        {
            Dummy dummy = new Dummy { NotNullOrWhiteSpace = "\t" };

            ValidationResult result = dummy.Validate();
            Assert.IsFalse(result.IsValid);
            Assert.AreSame(typeof(ValidateNotNullOrWhiteSpaceException), ((ValidationContextException)result.ValidationException).Flatten().First().GetType());
        }

		#region Mocks
		public class Dummy
		{
            [NotNullOrWhiteSpace]
            public string NotNullOrWhiteSpace { get; set; }
		}
		#endregion
	}
}